package demo2.x.com;

import com.opensymphony.xwork2.ActionSupport;
import com.utils.SsoChecks;
import demo1.x.com.utils.Demo1Tool;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by sanmao on 2017/6/12.
 */
public class Demo2Action extends ActionSupport{
    private String gotoUrl;

    public String getGotoUrl() {
        return gotoUrl;
    }

    public void setGotoUrl(String gotoUrl) {
        this.gotoUrl = gotoUrl;
    }

    public String main() {
        HttpServletRequest request = ServletActionContext.getRequest();
        Cookie[] cookies = request.getCookies();
        if (cookies != null) {
            for (Cookie cookie : cookies) {
                if (cookie.equals("ssohxw")) {
                    String result = Demo1Tool.doGet("http://check.x.com/sso/checkCookies", cookie.getName(), cookie.getValue());
                    if (result.equals("1")) {
                        return SUCCESS;
                    }
                }
            }
        }

        gotoUrl = "http://demo2.x.com/demo2/action.action";
        return LOGIN;
    }
}
